<template>
  <div class="login-container">
    <!-- 添加面包屑导航 -->
    <el-breadcrumb separator-class="el-icon-arrow-right" class="breadcrumb">
      <el-breadcrumb-item :to="{ path: '/' }">首页</el-breadcrumb-item>
      <el-breadcrumb-item>登录</el-breadcrumb-item>
    </el-breadcrumb>
    <div class="login-form">
      <el-input
          v-model="username"
          placeholder="请输入用户名"
          prefix-icon="el-icon-user"
      ></el-input>
      <el-input
          v-model="password"
          type="password"
          placeholder="请输入密码"
          prefix-icon="el-icon-lock"
          style="margin-top: 20px;"
      ></el-input>
      <el-button
          type="danger"
          style="width: 100%; margin-top: 20px;"
          @click="handleLogin"
      >
        登录
      </el-button>
      <div class="footer-links" >
        <span>忘记密码</span>
        <span>忘记账户名</span>
        <span>免费注册</span>
      </div>
    </div>
  </div>
</template>

<script>
import api from "@/api";

export default {

  name: "Login",
  data() {
    return {
      username: "",
      password: ""
    };
  },
  methods: {
    handleLogin() {
      //  向我们 6666 服务器发送 登录请求
      // 登录逻辑
      api.get("/api/login", {
        params: {
          user: this.username,
          pwd: this.password
        }
      }).then(res => {
        // 如果 登录成功就保存到vuex 里，并跳转到，首页
        if (res.code === 200) {
          console.log("sq", res.serverData);
          this.$store.dispatch('setUser', res.serverData);
          this.$router.push({path: "/", query: {t: Date.now()}});

        } else {
          this.$message.error("用户名或密码错误！");
        }
        console.log(res);
      })

    }
  }
};
</script>

<style scoped>
.login-container {
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  background-color: #fff;
  position: relative;
  height: 400px;
  width: 1600px; /* 设置登录页面宽度为1600px */
  margin: 0 auto; /* 居中显示 */
}

.breadcrumb {
  position: absolute;
  top: 20px;
  left: 20px;
}

.login-form {
  background-color: #f0f0f0;
  padding: 40px;
  width: 350px;
  margin-top: 0;
  margin-left: 60px;
  margin-bottom: 0;
}

.footer-links {
  display: flex;
  justify-content: flex-end;
  margin-top: 15px;
  font-size: 13px;
  color: #999;
}

.footer-links span {
  margin-left: 10px;
  cursor: pointer;
}
</style>


